package com.lottery.game.controller.v2.login;

import com.lottery.game.common.Response;
import com.lottery.game.controller.v2.login.to.LoginTO;
import com.lottery.game.core.modules.service.app.v2.PassportService;
import com.lottery.game.core.validator.annotation.Validate;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

/**
 * @author : yinlin
 * @version : 1.0
 * @date : 2019-02-25 21:05
 * @Description :
 * @Copyright : Copyright (c) 2018
 * @Company : KeRuYun Technology(Beijing) Chengdu Co. Ltd.
 * @link : com.runshang.apps.cloudgame.controller.v2.login.LoginController
 */
@Slf4j
@RestController
@RequestMapping(value="/api/v2/")
@Api(tags="APP-用户登录相关接口-ok")
public class LoginController {

    @Autowired
    private PassportService passportService;

    @ApiOperation(
            value = "用户登陆",
            notes = "用户登陆,登陆成功返回token，ticket为base64加密的一个json，登陆后请求需要在header中携带ticket，可以反解base64，里面包含用户信息\n" +
                    "{\n" +
                    "  \"id\": 0,\n" +
                    "  \"username\": \"用户名\",\n" +
                    "  \"nickname\": \"昵称\",\n" +
                    "  \"phone\": \"手机号\",\n" +
                    "  \"loginTime\": 0,\n" +
                    "  \"sign\": \"签名\"\n" +
                    "}"
    )
    @RequestMapping(value = "login",
            method = RequestMethod.POST,
            consumes = MediaType.APPLICATION_JSON_VALUE,
            produces = MediaType.APPLICATION_JSON_VALUE)
    @Validate
    public Response<String> login(@RequestBody LoginTO loginTO) {
        return Response.build(passportService.login(loginTO.getUsername(), loginTO.getPassword()));
    }
}
